import { ADDCOUNR, MINUSCOUNR } from './action-types'
export function countReducer(state, action) {
  console.log("countReducer")
  state = state || {
    count: 100,
    type: '偶数'
  }
  switch (action.type) {
    case ADDCOUNR:
      if (action.num > 10) {
        action.num = 10
      }
      let newV = state.count + action.num;
      let newT = newV % 2 ? '奇数' : '偶数'
      return {
        ...state,
        count: newV,
        type: newT
      }
    case MINUSCOUNR:
      return {
        ...state,
        count: state.count - action.num,
        type: (state.count - action.num) % 2 ? '奇数' : '偶数'
      }
    default:
      return {
        ...state
      }
  }
}